package com.soft.javase.ch10.test.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/5/7
 * 4.获取String集合中最长的元素
 */
public class LongestString {
    public static void main(String[] args) {
        List<String> strings = Arrays.asList("Java", "Python", "C++", "JavaScript", "Go");

        Optional<String> longest = strings.stream()
                .reduce((s1, s2) -> s1.length() > s2.length() ? s1 : s2);

        longest.ifPresent(s -> System.out.println("最长的字符串: " + s));
    }
}
